﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Media3D;
using Eniux.Windows.ThreeDEngine.Helper;

namespace Eniux.Windows.ThreeDEngine.Base
{
    partial class EniuxViewport3D
    {
        #region 属性

        #region 操作手势

        #region PanGesture（平移操作手势）
        /// <summary>
        ///   平移操作手势属性
        /// </summary>
        public static readonly DependencyProperty PanGestureProperty = DependencyProperty.Register(
            "PanGesture",
            typeof(MouseGesture),
            typeof(EniuxViewport3D),
            new UIPropertyMetadata(new MouseGesture(MouseAction.RightClick, ModifierKeys.Shift)));

        /// <summary>
        /// 获取或设置平移操作手势
        /// </summary>
        public MouseGesture PanGesture
        {
            get { return (MouseGesture)this.GetValue(PanGestureProperty); }
            set { this.SetValue(PanGestureProperty, value); }
        }
        #endregion

        #region RotateGesture（旋转操作手势）
        /// <summary>
        ///  旋转操作手势属性
        /// </summary>
        public static readonly DependencyProperty RotateGestureProperty = DependencyProperty.Register(
            "RotateGesture",
            typeof(MouseGesture),
            typeof(EniuxViewport3D),
            new UIPropertyMetadata(new MouseGesture(MouseAction.RightClick)));

        /// <summary>
        /// 获取或设置旋转操作手势
        /// </summary>
        public MouseGesture RotateGesture
        {
            get { return (MouseGesture)GetValue(RotateGestureProperty); }
            set { SetValue(RotateGestureProperty, value); }
        }
        #endregion

        #region ZoomGesture（缩放操作手势）
        /// <summary>
        ///  缩放操作手势属性
        /// </summary>
        public static readonly DependencyProperty ZoomGestureProperty = DependencyProperty.Register(
            "ZoomGesture",
            typeof(MouseGesture),
            typeof(EniuxViewport3D),
            new UIPropertyMetadata(new MouseGesture(MouseAction.RightClick, ModifierKeys.Control)));

        /// <summary>
        /// 获取或设置缩放操作手势
        /// </summary>
        public MouseGesture ZoomGesture
        {
            get { return (MouseGesture)GetValue(ZoomGestureProperty); }
            set { SetValue(ZoomGestureProperty, value); }
        }
        #endregion

        #region ZoomRectangleGesture（矩形缩放操作手势）
        /// <summary>
        ///  矩形缩放操作手势属性
        /// </summary>
        public static readonly DependencyProperty ZoomRectangleGestureProperty =
            DependencyProperty.Register(
                "ZoomRectangleGesture",
                typeof(MouseGesture),
                typeof(EniuxViewport3D),
                new UIPropertyMetadata(
                    new MouseGesture(MouseAction.RightClick, ModifierKeys.Control | ModifierKeys.Shift)));

        /// <summary>
        /// 获取或设置矩形缩放操作手势
        /// </summary>
        public MouseGesture ZoomRectangleGesture
        {
            get { return (MouseGesture)GetValue(ZoomRectangleGestureProperty); }
            set { SetValue(ZoomRectangleGestureProperty, value); }
        }
        #endregion 

        #region ZoomExtentsGesture（缩放视场操作手势）
        /// <summary>
        /// 缩放视场操作手势属性
        /// </summary>
        public static readonly DependencyProperty ZoomExtentsGestureProperty =
            DependencyProperty.Register(
                "ZoomExtentsGesture",
                typeof(InputGesture),
                typeof(EniuxViewport3D),
                new UIPropertyMetadata(new KeyGesture(Key.E, ModifierKeys.Control | ModifierKeys.Shift)));

        /// <summary>
        /// 获取或设置缩放视场操作手势
        /// </summary>
        public InputGesture ZoomExtentsGesture
        {
            get { return (InputGesture)GetValue(ZoomExtentsGestureProperty); }
            set { SetValue(ZoomExtentsGestureProperty, value); }
        } 
        #endregion
        #endregion

        #region ZoomExtentsWhenLoaded（是否在Load时启用缩放）
        /// <summary>
        /// 是否在Load时启用缩放属性
        /// </summary>
        public static readonly DependencyProperty ZoomExtentsWhenLoadedProperty =
            DependencyProperty.Register(
                "ZoomExtentsWhenLoaded", typeof(bool), typeof(EniuxViewport3D), new UIPropertyMetadata(false));

        /// <summary>
        /// 获取或设置是否在Load时启用缩放
        /// </summary>
        public bool ZoomExtentsWhenLoaded
        {
            get { return (bool)GetValue(ZoomExtentsWhenLoadedProperty); }
            set { SetValue(ZoomExtentsWhenLoadedProperty, value); }
        } 
        #endregion

        #region ChangeFieldOfViewGesture（改变视图手势）
        /// <summary>
        ///   改变视图手势属性
        /// </summary>
        public static readonly DependencyProperty ChangeFieldOfViewGestureProperty =
            DependencyProperty.Register(
                "ChangeFieldOfViewGesture",
                typeof(MouseGesture),
                typeof(EniuxViewport3D),
                new UIPropertyMetadata(new MouseGesture(MouseAction.RightClick, ModifierKeys.Alt)));

        /// <summary>
        /// 获取或设置改变摄像机的水平视角手势
        /// </summary>
        public MouseGesture ChangeFieldOfViewGesture
        {
            get { return (MouseGesture)GetValue(ChangeFieldOfViewGestureProperty); }
            set { SetValue(ChangeFieldOfViewGestureProperty, value); }
        }  
        #endregion

        #region ChangeLookAtGesture（改变观察手势）
        /// <summary>
        ///   改变观察手势属性
        /// </summary>
        public static readonly DependencyProperty ChangeLookAtGestureProperty =
            DependencyProperty.Register(
                "ChangeLookAtGesture",
                typeof(MouseGesture),
                typeof(EniuxViewport3D),
                new UIPropertyMetadata(new MouseGesture(MouseAction.RightDoubleClick)));

        /// <summary>
        /// 获取或设置改变观察手势
        /// </summary>
        public MouseGesture ChangeLookAtGesture
        {
            get { return (MouseGesture)GetValue(ChangeLookAtGestureProperty); }
            set { SetValue(ChangeLookAtGestureProperty, value); }
        } 
        #endregion

        #endregion

        #region 公共方法
         /// <summary>
        /// 
        /// </summary>
        /// <param name="animationTime"></param>
        public void ZoomExtents(double animationTime = 0)
        {
            if (this.cameraController != null)
            {
                this.cameraController.ZoomExtents();
            }
        }

        /// <summary>
        /// 缩放至指定范围的边界框
        /// </summary>
        /// <param name="bounds"></param>
        /// <param name="animationTime"></param>
        public void ZoomExtents(Rect3D bounds, double animationTime = 0)
        {
            CameraHelper.ZoomExtents(this.Camera, this.Viewport, bounds, animationTime);
        }
        #endregion
    }
}
